<#assign title="仪表盘", index="layui-this">
<#include 'header.ftl'>
<div class="layui-body my-body">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-xs6 layui-col-md3">
            <div class="card">
                <div class="card-body">
                    <div class="clearfix">
                        <div class="float-left">
                            <i class="layui-icon layui-icon-user icon-user"></i>
                        </div>
                        <div class="float-right">
                            <div class="val">
                                <h3 title="总人数" id="person_num">0</h3>
                            </div>
                            <div class="text-muted">
                                <i class="layui-icon-note layui-icon"></i> 总人数
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md3">
            <div class="card">
                <div class="card-body">
                    <div class="clearfix">
                        <div class="float-left">
                            <i class="layui-icon layui-icon-group icon-group"></i>
                        </div>
                        <div class="float-right">
                            <div class="val">
                                <h3 title="总成果数" id="result_num">0</h3>
                            </div>
                            <div class="text-muted">
                                <i class="layui-icon-list layui-icon"></i> 总成果数
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md3">
            <div class="card">
                <div class="card-body">
                    <div class="clearfix">
                        <div class="float-left">
                            <i class="layui-icon layui-icon-home icon-home"></i>
                        </div>
                        <div class="float-right">
                            <div class="val">
                                <h3 title="总类别数" id="type_num">0</h3>
                            </div>
                            <div class="text-muted">
                                <i class="layui-icon-survey layui-icon"></i> 总类别数
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md3">
            <div class="card">
                <div class="card-body">
                    <div class="clearfix">
                        <div class="float-left">
                            <i class="layui-icon layui-icon-chat icon-user"></i>
                        </div>
                        <div class="float-right">
                            <div class="val">
                                <h3 title="未审核数" id="unaudited_num">0</h3>
                            </div>
                            <div class="text-muted">
                                <i class="layui-icon-note layui-icon"></i> 未审核数目
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md9">
            <div id="test" style="width: 900px;height:520px;"> </div>
        </div>
        <div class="layui-col-md3">
            <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;">
                <legend>系统设置</legend>
                <div class="layui-form" lay-filter="setting">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: auto">自动审核注册</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="autoRegister" lay-skin="switch" lay-filter="autoRegister" lay-text="打开|关闭">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: auto">自动审核成果</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="autoResult" lay-skin="switch" lay-filter="autoResult" lay-text="打开|关闭">
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
</div>

<script type="text/html" id="person_num_script">
    <h3 title="总人数">{{d}}</h3>
</script>
<script type="text/html" id="result_num_script">
    <h3 title="总成果数">{{d}}</h3>
</script>
<script type="text/html" id="type_num_script">
    <h3 title="总类别数">{{d}}</h3>
</script>
<script type="text/html" id="unaudited_num_script">
    <h3 title="未审核数">{{d}}</h3>
</script>
<script src="/js/echarts.min.js"></script>
<script src="/js/echarts/calendar.js"></script>
<script>
    layui.use(['element', 'laytpl', 'form'], function () {
        var element = layui.element,
            $ = layui.$,
            laytpl = layui.laytpl,
            form = layui.form;

        $.calender(document.getElementById('test'))

        $.get('/user/count', function (data) {
            $('#person_num').html(data.payload)
        });

        $.get('/result/count', function (data) {
            $('#result_num').html(data.payload)
        });

        $.get('/type/count', function (data) {
            $('#type_num').html(data.payload)
        });

        $.get('/result/count?resultStatus=UNAUDITED', function (data) {
            $('#unaudited_num').html(data.payload)
        });

        $.get('/setting/getAll', function (result) {
            if (result.success) {
                form.val('setting', {
                    "autoRegister": result.payload.isRegister,
                    "autoResult": result.payload.autoAudited
                });
            }
        })

        form.on('switch(autoRegister)', function(data){
            $.post('/setting/update', {"isRegister": data.elem.checked}, function (result) {
                if (result.success) {
                    data.elem.checked = result.payload.isRegister
                } else {
                    data.elem.checked = !data.elem.checked;
                }
            })
        });

        form.on('switch(autoResult)', function(data){
            $.post('/setting/update', {"autoAudited": data.elem.checked}, function (result) {
                if (result.success) {
                    data.elem.checked = result.payload.autoAudited
                } else {
                    data.elem.checked = !data.elem.checked;
                }
            })
        });

        function copyArr(arr) {
            let res = []
            for (let i = 0; i < arr.length; i++) {
                res.push(arr[i])
            }
            return res
        }
    });
</script>
<#include 'footer.ftl' >